package com.zhxh.nzpos.goods;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.dao.SuppliersDao;
import com.zhxh.nzpos.model.Suppliers;
import com.zhxh.nzpos.sell.ItemDeleteCallback;

/**
 * 供货商管理
 * 
 * @author wangzt
 * 
 */
public class SuppliersAddActivity extends BaseActivity implements
		ItemDeleteCallback {

	private ArrayList<Suppliers> suppliersItems;
	private SupplierListAdapter listAdapter;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_supplier_add);
		initViews();

	}

	private void initViews() {

	}

	public void onDelete(int pos) {
		suppliersItems.remove(pos);
		listAdapter.notifyDataSetChanged();
	}

	public void add(View view) {
		EditText name = (EditText) findViewById(R.id.name);
		EditText address = (EditText) findViewById(R.id.address);
		EditText contact = (EditText) findViewById(R.id.contact);
		EditText phone = (EditText) findViewById(R.id.phone);
		EditText mobile = (EditText) findViewById(R.id.mobile);
		boolean isOK = true;
		
		if( name.getText().toString().length() == 0 )
		{
			name.setError( "请输入供货商名称" );
			isOK = false;
		}
		if( address.getText().toString().length() == 0 ){
			address.setError( "请输入供货商地址" );
			isOK = false;
		}
		if( contact.getText().toString().length() == 0 ){
			contact.setError( "请输入联系人" );
			isOK = false;
		}
		if( phone.getText().toString().length() == 0 ){
			phone.setError( "请输入电话" );
			isOK = false;
		}
		if(!isOK) return;
		
		Suppliers supplier = new Suppliers();
		supplier.setCompany(name.getText().toString());
		supplier.setAddress(address.getText().toString());
		supplier.setContactPerson(contact.getText().toString());
		supplier.setPhone(phone.getText().toString());
		supplier.setMobile(mobile.getText().toString());
		SuppliersDao dao = new SuppliersDao(getApplicationContext());
		dao.save(supplier);

		Intent i = new Intent();
		Bundle b = new Bundle();
		b.putSerializable("supplier", supplier);
		i.putExtras(b);

		setResult(RESULT_OK, i);
		finish();

	}

	public void cancel(View view) {

		finish();

	}

	@Override
	public void onUpdate() {
		// TODO Auto-generated method stub
		
	}
}
